package com.tanhua.server.service;

import com.alibaba.fastjson.JSON;
import io.jsonwebtoken.impl.crypto.MacProvider;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/10 9:23
 *
 *  消息发送工具类
 */
@Service
public class MqMessageService {


    @Autowired
    private AmqpTemplate amqpTemplate;


    // 发送日治消息
    public void sendLogMessage(Long userId, String type, String key, String busId){

        try {
            Map map = new HashMap();
            map.put("userId", userId.toString());
            map.put("type", type);
            map.put("logTime", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
            map.put("busId", busId);
            String message = JSON.toJSONString(map);
            amqpTemplate.convertAndSend("tanhua.log.exchange", "log."+key, message);
        } catch (AmqpException e) {
            e.printStackTrace();
        }

    }


    // 发送动态审核消息
    public void sendAudiMessage(String movementId){

        try {
            amqpTemplate.convertAndSend("tanhua.audit.exchage", "audit.movement", movementId);
        } catch (AmqpException e) {
            e.printStackTrace();
        }

    }





}
